import request from "@/uitls/request";
import {
  GetListResponseData,
  GetListResponseRecords,
  MenuResponseData,
} from "./type";
enum API {
  LIST_ROLE_URL = "/admin/acl/role/", //获取列表page limit roleName
  ADD_ROLE_URL = "/admin/acl/role/save/", //增加角色 post
  REMOVE_ROLE_URL = "/admin/acl/role/remove/", //删除角色 delete
  UPDATE_ROLE_URL = "/admin/acl/role/update/", //修改角色 put
  //获取全部的菜单与按钮的数据
  ALLPERMISSTION = "/admin/acl/permission/toAssign/",
  //给相应的职位分配权限
  SETPERMISTION_URL = "/admin/acl/permission/doAssign/?",
}
// 获取列表
export const reqGetRoleList = (page: number, limit: number, roleName: string) =>
  request.get<any, GetListResponseData>(
    API.LIST_ROLE_URL + `${page}/${limit}?roleName=${roleName}`
  );
// 添加与修改
export const reqAddOrUpdateUser = (data: GetListResponseRecords) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATE_ROLE_URL, data);
  } else {
    return request.post<any, any>(API.ADD_ROLE_URL, data);
  }
};
// 删除角色
export const reqRemoveUser = (id: number | string) =>
  request.delete<any, any>(API.REMOVE_ROLE_URL + id);
// 根据用户获取菜单
export const reqAllRole = (roleId: number | string) =>
  request.get<any, MenuResponseData>(API.ALLPERMISSTION + roleId);
// 给用户分配权限
export const reqSetUserRole = (
  roleId: number,
  permissionId: (number | string)[]
) =>
  request.post<any, any>(
    API.SETPERMISTION_URL + `roleId=${roleId}&permissionId=${permissionId}`
  );
